C++ ifstream eof()的使用 | 您所在的位置:网站首页 › while eof怎么结束 › C++ ifstream eof()的使用 |
C++ ifstream eof() 的使用
eof() 的使用方法1
ifstream.eof() 读到文件结束符时返回true。 大家可能有一个误区,认为读到文件结束符就是读到文件的最后一个字符。 其实不然,文件结束符是文件最后一个字符的下一个字符0xFF,eof() 读到文件结束符0xFF时返回true。 代码验证1先来看看如下这段代码2: #include #include #include using namespace std; int main() { char ch = 'x'; ifstream fin("test.txt" ); if (!fin) { cout fin.get(ch); cout cout fin.get(ch); if (fin.fail()) { cout cout //fin.get(ch); fin >> s; if (fin.fail()) { cout |
CopyRight 2018-2019 实验室设备网 版权所有 |